package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.zhgd.domain.NAsphaltMatchHot;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NAsphaltMatchHotVo;
import com.ruoyi.zhgd.domain.bo.NAsphaltMatchHotBo;
import com.ruoyi.zhgd.service.INAsphaltMatchHotService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热料配置表
 *
 * @author tll
 * @date 2023-10-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/asphaltMatchHot")
public class NAsphaltMatchHotController extends BaseController {

    private final INAsphaltMatchHotService iNAsphaltMatchHotService;

    /**
     * 查询热料配置表列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NAsphaltMatchHotVo> list(NAsphaltMatchHotBo bo, PageQuery pageQuery) {
        return iNAsphaltMatchHotService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出热料配置表列表
     */
    @SaCheckLogin
    @Log(title = "热料配置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NAsphaltMatchHotBo bo, HttpServletResponse response) {
        List<NAsphaltMatchHotVo> list = iNAsphaltMatchHotService.queryList(bo);
        ExcelUtil.exportExcel(list, "热料配置表", NAsphaltMatchHotVo.class, response);
    }

    /**
     * 获取热料配置表详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NAsphaltMatchHotVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNAsphaltMatchHotService.queryById(id));
    }

    /**
     * 新增热料配置表
     */
    @SaCheckLogin
    @Log(title = "热料配置表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NAsphaltMatchHotBo bo) {
        return toAjax(iNAsphaltMatchHotService.insertByBo(bo));
    }

    /**
     * 修改热料配置表
     */
    @SaCheckLogin
    @Log(title = "热料配置表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NAsphaltMatchHotBo bo) {
        return toAjax(iNAsphaltMatchHotService.updateByBo(bo));
    }

    /**
     * 删除热料配置表
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "热料配置表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNAsphaltMatchHotService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 获取指定生产级配热料筛分级配列表
     * @param matchId 生产配比主键
     * @return 生产配比热料筛分级配列表
     */
    @GetMapping("/list/{matchId}")
    public R<List<NAsphaltMatchHot>> matchList(@PathVariable("matchId") String matchId) {
        return R.ok(iNAsphaltMatchHotService.matchList(matchId));
    }

    /**
     * 添加配比热料筛分级配
     * @param list
     * @param matchId
     * @return
     */
    @PostMapping("/save/{matchId}")
    public R save(@RequestBody List<NAsphaltMatchHot> list, @PathVariable("matchId") String matchId) {
        iNAsphaltMatchHotService.save(list, matchId);
        return R.ok();
    }
}
